package com.xja.seckill.products.controller;

import com.xja.seckill.order.commons.JsonBean;
import com.xja.seckill.products.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/product")
public class ProductsController {
    @Autowired
    private ProductService productService;

    @RequestMapping("getProductById")
    public JsonBean getProductById(Integer id){
        return new JsonBean(0,"ok",productService.getProductById (id));
    }

    @RequestMapping("openSeckill")
    public JsonBean openSeckill(Integer id,Long count){
        return productService.openSeckill(id,count);
    }

    @RequestMapping("closeSeckill")
    public JsonBean closeSeckill(Integer id){
        return productService.closeSeckill(id);
    }

    @RequestMapping("reducerStock")
    public JsonBean reducerStock(Integer productId){
        return new JsonBean (0,"ok",productService.reducerStock (productId));
    }

}
